//
//  PlayView.m
//  27-block练习播放按钮
//
//  Created by 殷殷明静 on 16/8/19.
//  Copyright © 2016年 殷明静. All rights reserved.
//

#import "PlayView.h"
#import "UIView+YMJ_view.h"
@interface PlayView ()
@property (nonatomic, copy) void (^play)(UIButton *play);
@property (nonatomic, copy) void (^pause)(UIButton *pause);
@property (nonatomic, copy) void (^last)(UIButton *last);
@property (nonatomic, copy) void (^next)(UIButton *next);
@property (nonatomic, strong) UIButton *play_btn;
@property (nonatomic, strong) UIButton *last_btn;
@property (nonatomic, strong) UIButton *next_btn;
@end
@implementation PlayView
- (void)play:(void (^)(UIButton *))play pause:(void (^)(UIButton *))pause {
    _play = play;
    _pause = pause;
}
- (void)lastPlay:(void (^)(UIButton *))last_btn {
    _last = last_btn;
}
- (void)nextPlay:(void (^)(UIButton *))next_btn {
    _next = next_btn;
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setup];
    }
    return self;
}
- (void)setup {
    _play_btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_play_btn];
    _last_btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_last_btn];
    _next_btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_next_btn];
}
- (void)layoutSubviews {
    [super layoutSubviews];
    _play_btn.frame = CGRectMake(0, 0, 80, 80);
    _play_btn.center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
    [_play_btn setBackgroundImage:[UIImage imageNamed:@"hp_player_btn_play_highlight"] forState:0];
   
    [_play_btn addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
    _last_btn.ymj_centerY = _play_btn.center.y;
    _last_btn.ymj_centerX = 30;
    _last_btn.ymj_width = 60;
    _last_btn.ymj_height = 60;
    [_last_btn addTarget:self action:@selector(lastAction:) forControlEvents:UIControlEventTouchUpInside];
    [_last_btn setBackgroundImage:[UIImage imageNamed:@"player_btn_pre_normal"] forState:0];
    _next_btn.ymj_centerY = _play_btn.center.y;
    _next_btn.ymj_centerX = self.bounds.size.width - 30;
    _next_btn.ymj_width = 60;
    _next_btn.ymj_height = 60;
    [_next_btn setBackgroundImage:[UIImage imageNamed:@"hp_player_btn_next_highlight"] forState:0];
    [_next_btn addTarget:self action:@selector(nextAction:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)lastAction:(UIButton *)btn {
    self.last(btn);
}
- (void)nextAction:(UIButton *)btn {
    self.next(btn);
}
- (void)play:(UIButton *)btn {
     [_play_btn setBackgroundImage:[UIImage imageNamed:@"hp_player_btn_pause_highlight"] forState:0];
    [_play_btn removeTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
    [_play_btn addTarget:self action:@selector(pause:) forControlEvents:UIControlEventTouchUpInside];
    self.play(btn);
}
- (void)pause:(UIButton *)btn {
    [_play_btn setBackgroundImage:[UIImage imageNamed:@"hp_player_btn_play_highlight"] forState:0];
    [_play_btn removeTarget:self action:@selector(pause:) forControlEvents:UIControlEventTouchUpInside];
    [_play_btn addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
    self.pause(btn);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
